package com.itheima.app.controller.omsController;

import com.itheima.app.manager.omsManager.OmsOrderManager;
import com.itheima.commons.R;
import com.itheima.dto.OmsOrderDto;
import com.itheima.vo.OmsOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 订单相关
 */
@CrossOrigin    //跨域
@RestController
public class OmsOrderController {
    @Autowired
    OmsOrderManager omsOrderManager;

    /**
     * 查询订单
     *
     * @param omsOrderDto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/order/list")
    public R findByParams(OmsOrderDto omsOrderDto,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return omsOrderManager.findByParams(omsOrderDto, pageNum, pageSize);
    }

    /**
     * 获取订单详情：订单信息、商品信息、操作记录
     *
     * @param id
     * @return
     */
    @GetMapping("/order/{id}")
    public R getInfoByOrderId(@PathVariable(required = true) Integer id) {
        OmsOrderVo vo = omsOrderManager.getInfoByOrderId(id);
        return R.ok(vo);
    }

    /**
     * 批量删除订单
     *
     * @param ids
     * @return
     */
    @PostMapping("/order/delete")
    public R updateDelete(Integer[] ids) {
        omsOrderManager.updateDelete(ids);
        return R.ok(1);
    }

    /**
     * 批量关闭订单
     *
     * @return
     */
    @PostMapping("/order/update/close")
    public R updateClose(Integer[] ids, String note) {
        omsOrderManager.updateClose(ids, note);
        return R.ok(null);
    }

    /**
     * 批量发货
     *
     * @param maps
     * @return
     */
    @PostMapping("/order/update/delivery")
    public R updateDelivery(LinkedHashMap[] maps) {
        omsOrderManager.updateDelivery(maps);
        return R.ok(null);
    }

    /**
     * 修改收货人信息
     *
     * @return
     */
    @PostMapping("/order/update/receiverInfo")
    public R updateReceiverInfo(@RequestBody Map map) {
        omsOrderManager.updateReceiverInfo(map);
        return R.ok(null);
    }

    /**
     * 备注订单
     *
     * @param id
     * @param note
     * @param status
     * @return
     */
    @PostMapping("/order/update/note")
    public R updateNote(Integer id, String note, Integer status) {
        omsOrderManager.updateNote(id, note, status);
        return R.ok(null);
    }

    /**
     * 修改订单费用信息
     *
     * @return
     */
    @PostMapping("/order/update/moneyInfo")
    public R updateMoneyInfo(@RequestBody Map map) {
        omsOrderManager.updateMoneyInfo(map);
        return R.ok(null);
    }
}
